<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>面向对象选项卡</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <style>
        .active{
            background-color: #cc0033;
        }
        button{
            width: 80px;height: 30px;
        }
        .box div{
            border: 1px solid black;
            width: 247px;
            height: 200px;
            display: none;
            text-align: center;
            line-height: 200px;
        }
    </style>
</head>
<body>
<div  class="box">
    <button class="active">first</button>
    <button>second</button>
    <button>third</button>
    <div style="display: block">第一个</div>
    <div>第二个</div>
    <div>第三个</div>
</div>
<script>
    var oBox=null;
    var aBtn=null;
    var aDiv=null;
    window.onload=function () {
        oBox=document.querySelector("#box");
        aBtn=document.querySelectorAll("button");
        aDiv=document.querySelectorAll(".box div");
        init()
    };

    function init() {
        for(var i=0;i<aBtn.length;i++){
            aBtn[i].index=i;
            aBtn[i].onclick=dianji;
        }
    }
    function dianji () {
        for(var i=0;i<aBtn.length;i++){
           aBtn[i].className="";
           aDiv[i].style.display="none"
        }
        aBtn[this.index].className="active";
        aDiv[this.index].style.display="block"
    }
</script>
</body>
</html>